package com.example.assistant;


import java.util.HashMap;
import java.util.Map;
/**
 * @author Leo
 * @version 1.0.0
 * @since 11
 * 意图识别模块（规则+上下文）
 */

public class IntentRecognizer {

    private static final Map<String, String[]> INTENT_KEYWORDS = new HashMap<>();
    private static String lastIntent = null;

    static {
        INTENT_KEYWORDS.put("light", new String[]{"灯", "亮度"});
        INTENT_KEYWORDS.put("ac", new String[]{"空调", "温度", "制冷", "制热"});
        INTENT_KEYWORDS.put("curtain", new String[]{"窗帘", "拉开", "关上"});
        INTENT_KEYWORDS.put("tv", new String[]{"电视", "音量", "频道", "静音"});
        INTENT_KEYWORDS.put("fan", new String[]{"风扇", "风速", "摆头"});
        INTENT_KEYWORDS.put("lock", new String[]{"门锁", "上锁", "解锁"});
        INTENT_KEYWORDS.put("humidifier", new String[]{"加湿器", "湿度", "自动模式"});
    }
    public static String detectIntent(String query) {
        for (Map.Entry<String, String[]> entry : INTENT_KEYWORDS.entrySet()) {
            String intent = entry.getKey();
            for (String keyword : entry.getValue()) {
                if (query.contains(keyword)) {
                    lastIntent = intent;
                    return intent;
                }
            }
        }
        return lastIntent != null ? lastIntent : "other";
    }
}